//
//  IncomeHeaderView.swift
//  TianTianBiTing
//
//  Created by Gox mac 2 on 2019/2/25.
//  Copyright © 2019 Gox_WallyDiao. All rights reserved.
//

import UIKit

class IncomeHeaderView: UIView {
    var dayBtn:UIButton = {
        let btn = UIButton.init(type: .custom)
        btn.setTitle("日榜", for: .normal)
        btn.frame = FRAME_CGFloat(0, 0, 90, 32)
        btn.backgroundColor = UIColor.clear
        btn.setTitleColor(.black, for: .normal)
        btn.layer.cornerRadius = 16
        btn.addTarget(self, action: #selector(dateAction), for: .touchUpInside)
        btn.tag = 11
        return btn
    }()
    var weekBtn:UIButton = {
        let btn = UIButton.init(type: .custom)
        btn.setTitle("周榜", for: .normal)
        btn.frame = FRAME_CGFloat(90, 0, 90, 32)
        btn.backgroundColor = UIColor.clear
        btn.setTitleColor(.black, for: .normal)
        btn.layer.cornerRadius = 16
        btn.addTarget(self, action: #selector(dateAction), for: .touchUpInside)
        btn.tag = 12
        return btn
    }()
    var monthBtn:UIButton = {
        let btn = UIButton.init(type: .custom)
        btn.setTitle("月榜", for: .normal)
        btn.frame = FRAME_CGFloat(180, 0, 90, 32)
        btn.backgroundColor = UIColor.clear
        btn.setTitleColor(.black, for: .normal)
        btn.layer.cornerRadius = 16
        btn.addTarget(self, action: #selector(dateAction), for: .touchUpInside)
        btn.tag = 13
        return btn
    }()
    var dateBlock:((_ num:Int) -> Void)?
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = UIColor.clear
        setUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setUI() {
        
        let backImageView = UIImageView.init(frame: FRAME_CGFloat(SCREEN_WIDTH / 2 - 135, 10, 270, 32))
        self.addSubview(backImageView)
        backImageView.isUserInteractionEnabled = true
        backImageView.backgroundColor = RGB(252, 246, 165)
        backImageView.layer.cornerRadius = 16
        
        backImageView.addSubview(self.dayBtn)
        backImageView.addSubview(self.weekBtn)
        backImageView.addSubview(self.monthBtn)
        
        dayChangeColor()
        
    }
    
    @objc func dateAction(btn:UIButton) {
        dateBlock?(btn.tag)
        switch btn.tag {
        case 11:
            dayChangeColor()
        case 12:
            weekChangeColor()
        case 13:
            monthChangeColor()
        default:
            return
        }
    }
    
    func dayChangeColor() {
        UIView.animate(withDuration: 0.3) {
            self.dayBtn.backgroundColor = RGB(255, 237, 0)
            self.weekBtn.backgroundColor = .clear
            self.monthBtn.backgroundColor = .clear
        }
    }
    func weekChangeColor() {
        UIView.animate(withDuration: 0.3) {
            self.dayBtn.backgroundColor = .clear
            self.weekBtn.backgroundColor = RGB(255, 237, 0)
            self.monthBtn.backgroundColor = .clear
        }
    }
    func monthChangeColor() {
        UIView.animate(withDuration: 0.3) {
            self.dayBtn.backgroundColor = .clear
            self.weekBtn.backgroundColor = .clear
            self.monthBtn.backgroundColor = RGB(255, 237, 0)
        }
    }


}
